package com.qf.crm.service.impl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.qf.crm.dao.ProductDao;
import com.qf.crm.dao.impl.ProductDaoImpl;
import com.qf.crm.entity.Product;
import com.qf.crm.service.ProductService;
import com.qf.crm.utils.JdbcUtils;

public class ProductServiceImpl implements ProductService{

	private ProductDao productDao = new ProductDaoImpl();
	
	@Override
	public List<Product> getProductList() {
		Connection connection = null;
		try {
			connection = JdbcUtils.getConnection();
			connection.setAutoCommit(false);
			String sql="SELECT product_id as productId,product_name as productName,product_code as productCode,product_category_id as productCategoryId,price,founder_id as founderId,create_time as createTime,update_time as updateTime,flag FROM product";
			List<Product> list = productDao.getProductList(connection, sql, Product.class);
			connection.commit();
			return list;
		} catch (InstantiationException | IllegalAccessException | NoSuchFieldException | SecurityException
				| SQLException e) {
			
			if(connection!=null) {
				try {
					connection.rollback();
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
			}
			
			e.printStackTrace();
		}finally {
			JdbcUtils.close();
		}
		return null;
	}

}
